package cn.blunce.AutoTest;

/**
 * Created by Experiment on 2016/3/28 0028.
 */
public class Solution {
    public int romanToInt(String s) {
        char[] nums = s.toCharArray();
        int sum = 0;
        for (int i = 0; i < nums.length ; i++) {
            if (i==nums.length-1)
                sum+=CharToInt(nums[i]);
            else {
                int a_i = CharToInt(nums[i]),a_j=CharToInt(nums[i+1]);
                if (a_i>=a_j)
                    sum+=a_i;
                else
                    sum-=a_i;
            }
        }
        return sum;
    }

    private int CharToInt(char c) {
        switch (c) {
            case 'I':
                return 1;
            case 'V':
                return 5;
            case 'X':
                return 10;
            case 'L':
                return 50;
            case 'C':
                return 100;
            case 'D':
                return 500;
            case 'M':
                return 1000;
            default:
                return 0;
        }
    }

    public void test() {
        Solution s = new Solution();
        SolutionTest st = new SolutionTest() {
            protected Object inputParse(String input){
                return (Object)input;
            }

            protected Object outputParse(String output){
                return (Object) Integer.valueOf(output);
            }

            protected String inputAntiParse(Object input){
                return (String)input;
            }
            protected String outputAntiParse(Object output){
                return String.valueOf(output);
            }
            protected Object oneSolution(Solution s,Object input){
                return (Object) s.romanToInt((String)input);
            }
            protected boolean isRight(Object predict,Object result){
                return ((Integer)predict).equals((Integer)result);
            }
        };
        st.Test(s);
    }
}
